<template>
  <div class="content select-enterprise">
    <div class="head-top">
      <dc-header :title="'选择企业'" :icon="'icon-header-back'" :right-icon="''"></dc-header>
      <div v-if="companyList.length>0" class="textabovefrom">您是{{companyList.length}}个企业的成员，请选择本次想要查看的企业</div>
      <div v-else class="textabovefrom">暂无企业列表</div>
      <dc-cell class="ml20 mr20 no-border" :title="item.groupName" v-for="item in companyList" :key="item.groupName"
               :label="'角色：'+item.roleName" :width="'80'"
               img="static/icon_shops_company.png"
               rightIcon="icon-multi-enter"
               :rightStyle="{fontSize:'16px',color:'#7b78f2'}"
               @click.native="goto(item)"
               value="进入" :valStyle="{color:'#7b78f2'}">
      </dc-cell>
    </div>
  </div>
</template>
<script>
  import header from '@/common/plugins/header';
  import cell from '@/common/plugins/cell';
  import api from '@/common/api/login';
  import {mapActions} from 'vuex';
  import util from '@/common/util';

  export default {
    data () {
      return {
        companyList: []
      };
    },
    components: {
      'dc-header': header,
      'dc-cell': cell
    },
    methods: {
      ...mapActions({setStore: 'setStore', setPermission: 'setPermission'}),
      selectCompany () {
        api.selectCompany()
          .then(res => {
            this.companyList = res;
          });
      },
      goto (obj) {
        if (obj.storeCode) {
          api.getMulti(obj)
            .then(res => {
              util.loginTask(res);
            });
        } else {
          this.$router.push('/bindingShop');
        }
      }
    },
    activated () {
      this.selectCompany();
    }
  };
</script>
<style lang="scss">
  @import "../../assets/css/variable";
  .select-enterprise {
    .mint-cell {
      border-radius: px2rem(8px);
      height: px2rem(180px);
      img{
        width: px2rem(120px);
        height: px2rem(120px);
      }
    }
    .left-icon {
      float: left;
    }
    .ml20 {
      margin-left: px2rem(20px);
    }
    .mr20 {
      margin-right: px2rem(20px);
    }
    .list {
      height: px2rem(180px);
      line-height: px2rem(180px);
      border-radius: px2rem(8px);
    }
  }
</style>
